package com.bbva.kyfb.kyfbjpatlbh.dominiotlbh;

import java.math.BigDecimal;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.roo.addon.dod.RooDataOnDemand;
import org.springframework.stereotype.Component;

/**
 * The Class TtlsbcorDataOnDemand.
 */
@Component
@Configurable
@RooDataOnDemand(entity = Ttlsbcor.class)
public class TtlsbcorDataOnDemand {

	/** The rnd. */
	private Random rnd = new SecureRandom();

	/** The data. */
	private List<Ttlsbcor> data;

	/**
	 * Gets the new transient ttlsbcor.
	 *
	 * @param index the index
	 * @return the new transient ttlsbcor
	 */
	public Ttlsbcor getNewTransientTtlsbcor(int index) {
        Ttlsbcor obj = new Ttlsbcor();
        setEmbeddedIdClass(obj, index);
        setAudFmodific(obj, index);
        setAudUsuario(obj, index);
        setCodBancinte(obj, index);
        setCodCdnitr(obj, index);
        setCodCestad(obj, index);
        setCodClasemis(obj, index);
        setCodIdorigen(obj, index);
        setCodPaiscob(obj, index);
        setCodPaiscta(obj, index);
        setCodPaisdfis(obj, index);
        setCodProdcnf(obj, new Integer(999));
        setCodSitlote(obj, index);
        setCodSufprese(obj, index);
        setCodSwift(obj, index);
        setDesCuenorig(obj, index);
        setDesExtractx(obj, index);
        setDesFecprocr(obj, index);
        setDesNumremes(obj, index);
        setDesReflote(obj, index);
        setXsnContabix(obj, new Integer(1));
        setXtiNifid(obj, new Integer(0));
        return obj;
    }

	/**
	 * Sets the embedded id class.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setEmbeddedIdClass(Ttlsbcor obj, int index) {
		TtlsbcorPK embeddedIdClass;
		if (String.valueOf(index).length() > 7){
				embeddedIdClass = new TtlsbcorPK("c" + String.valueOf(index).substring(0, 6), "co" + index, String.valueOf(index).substring(0, 2), new Integer(index));
		}else{
        	embeddedIdClass = new TtlsbcorPK("c" + index, "codCliecash_" + index, "c_" + index, new Integer(index));
        }
        	obj.setId(embeddedIdClass);
    }

	/**
	 * Sets the aud fmodific.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setAudFmodific(Ttlsbcor obj, int index) {
        Date audFmodific = new GregorianCalendar(Calendar.getInstance().get(Calendar.YEAR), Calendar.getInstance().get(Calendar.MONTH), Calendar.getInstance().get(Calendar.DAY_OF_MONTH), Calendar.getInstance().get(Calendar.HOUR_OF_DAY), Calendar.getInstance().get(Calendar.MINUTE), Calendar.getInstance().get(Calendar.SECOND) + new Double(Math.random() * 1000).intValue()).getTime();
        obj.setAudFmodific(audFmodific);
    }

	/**
	 * Sets the aud usuario.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setAudUsuario(Ttlsbcor obj, int index) {
        String audUsuario = "audUsu_" + index;
        if (audUsuario.length() > 8) {
            audUsuario = audUsuario.substring(0, 8);
        }
        obj.setAudUsuario(audUsuario);
    }

	/**
	 * Sets the cod bancinte.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setCodBancinte(Ttlsbcor obj, int index) {
        String codBancinte = "codBancin_" + index;
        if (codBancinte.length() > 11) {
            codBancinte = codBancinte.substring(0, 11);
        }
        obj.setCodBancinte(codBancinte);
    }

	/**
	 * Sets the cod cdnitr.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setCodCdnitr(Ttlsbcor obj, int index) {
        String codCdnitr = "codCdnit_" + index;
        if (codCdnitr.length() > 10) {
            codCdnitr = codCdnitr.substring(0, 10);
        }
        obj.setCodCdnitr(codCdnitr);
    }

	/**
	 * Sets the cod cestad.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setCodCestad(Ttlsbcor obj, int index) {
        String codCestad = "codCestad_" + index;
        if (codCestad.length() > 11) {
            codCestad = codCestad.substring(0, 11);
        }
        obj.setCodCestad(codCestad);
    }

	/**
	 * Sets the cod clasemis.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setCodClasemis(Ttlsbcor obj, int index) {
        String codClasemis = "c_" + index;
        if (codClasemis.length() > 3) {
            codClasemis = codClasemis.substring(0, 3);
        }
        obj.setCodClasemis(codClasemis);
    }

	/**
	 * Sets the cod idorigen.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setCodIdorigen(Ttlsbcor obj, int index) {
        String codIdorigen = "codIdorigen_" + index;
        if (codIdorigen.length() > 15) {
            codIdorigen = codIdorigen.substring(0, 15);
        }
        obj.setCodIdorigen(codIdorigen);
    }

	/**
	 * Sets the cod paiscob.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setCodPaiscob(Ttlsbcor obj, int index) {
        String codPaiscob = "c" + index;
        if (codPaiscob.length() > 2) {
            codPaiscob = codPaiscob.substring(0, 2);
        }
        obj.setCodPaiscob(codPaiscob);
    }

	/**
	 * Sets the cod paiscta.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setCodPaiscta(Ttlsbcor obj, int index) {
        String codPaiscta = "c" + index;
        if (codPaiscta.length() > 2) {
            codPaiscta = codPaiscta.substring(0, 2);
        }
        obj.setCodPaiscta(codPaiscta);
    }

	/**
	 * Sets the cod paisdfis.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setCodPaisdfis(Ttlsbcor obj, int index) {
        String codPaisdfis = "c" + index;
        if (codPaisdfis.length() > 2) {
            codPaisdfis = codPaisdfis.substring(0, 2);
        }
        obj.setCodPaisdfis(codPaisdfis);
    }

	/**
	 * Sets the cod prodcnf.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setCodProdcnf(Ttlsbcor obj, int index) {
        BigDecimal codProdcnf = BigDecimal.valueOf(index);
        obj.setCodProdcnf(codProdcnf);
    }

	/**
	 * Sets the cod sitlote.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setCodSitlote(Ttlsbcor obj, int index) {
        String codSitlote = "co_" + index;
        if (codSitlote.length() > 4) {
            codSitlote = codSitlote.substring(0, 4);
        }
        obj.setCodSitlote(codSitlote);
    }

	/**
	 * Sets the cod sufprese.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setCodSufprese(Ttlsbcor obj, int index) {
        String codSufprese = "c_" + index;
        if (codSufprese.length() > 3) {
            codSufprese = codSufprese.substring(0, 3);
        }
        obj.setCodSufprese(codSufprese);
    }

	/**
	 * Sets the cod swift.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setCodSwift(Ttlsbcor obj, int index) {
        String codSwift = "codSwift_" + index;
        if (codSwift.length() > 11) {
            codSwift = codSwift.substring(0, 11);
        }
        obj.setCodSwift(codSwift);
    }

	/**
	 * Sets the des cuenorig.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setDesCuenorig(Ttlsbcor obj, int index) {
        String desCuenorig = "desCuenorig_" + index;
        if (desCuenorig.length() > 35) {
            desCuenorig = desCuenorig.substring(0, 35);
        }
        obj.setDesCuenorig(desCuenorig);
    }

	/**
	 * Sets the des extractx.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setDesExtractx(Ttlsbcor obj, int index) {
        String desExtractx = "desExtractx_" + index;
        if (desExtractx.length() > 20) {
            desExtractx = desExtractx.substring(0, 20);
        }
        obj.setDesExtractx(desExtractx);
    }

	/**
	 * Sets the des fecprocr.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setDesFecprocr(Ttlsbcor obj, int index) {
        String desFecprocr = "desFec_" + index;
        if (desFecprocr.length() > 8) {
            desFecprocr = desFecprocr.substring(0, 8);
        }
        obj.setDesFecprocr(desFecprocr);
    }

	/**
	 * Sets the des numremes.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setDesNumremes(Ttlsbcor obj, int index) {
        String desNumremes = "desNumremes_" + index;
        if (desNumremes.length() > 15) {
            desNumremes = desNumremes.substring(0, 15);
        }
        obj.setDesNumremes(desNumremes);
    }

	/**
	 * Sets the des reflote.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setDesReflote(Ttlsbcor obj, int index) {
        String desReflote = "desReflote_" + index;
        if (desReflote.length() > 40) {
            desReflote = desReflote.substring(0, 40);
        }
        obj.setDesReflote(desReflote);
    }

	/**
	 * Sets the xsn contabix.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setXsnContabix(Ttlsbcor obj, int index) {
        BigDecimal xsnContabix = BigDecimal.valueOf(index);
        obj.setXsnContabix(xsnContabix);
    }

	/**
	 * Sets the xti nifid.
	 *
	 * @param obj the obj
	 * @param index the index
	 */
	public void setXtiNifid(Ttlsbcor obj, int index) {
        Character xtiNifid = new Character('N');
        obj.setXtiNifid(xtiNifid);
    }

	/**
	 * Gets the specific ttlsbcor.
	 *
	 * @param index the index
	 * @return the specific ttlsbcor
	 */
	public Ttlsbcor getSpecificTtlsbcor(int index) {
        init();
        if (index < 0) index = 0;
        if (index > (data.size() - 1)) index = data.size() - 1;
        Ttlsbcor obj = data.get(index);
        return Ttlsbcor.findTtlsbcor(obj.getId());
    }

	/**
	 * Gets the random ttlsbcor.
	 *
	 * @return the random ttlsbcor
	 */
	public Ttlsbcor getRandomTtlsbcor() {
        init();
        Ttlsbcor obj = data.get(rnd.nextInt(data.size()));
        return Ttlsbcor.findTtlsbcor(obj.getId());
    }

	/**
	 * Modify ttlsbcor.
	 *
	 * @param obj the obj
	 * @return true, if successful
	 */
	public boolean modifyTtlsbcor(Ttlsbcor obj) {
        return false;
    }

	/**
	 * Inits the.
	 */
	public void init() {
        data = Ttlsbcor.findTtlsbcorEntries(0, 10);
        if (data == null) throw new IllegalStateException("Find entries implementation for 'Ttlsbcor' illegally returned null");
        if (!data.isEmpty()) {
            return;
        }
        
        data = new ArrayList<com.bbva.kyfb.kyfbjpatlbh.dominiotlbh.Ttlsbcor>();
        for (int i = 0; i < 10; i++) {
            Ttlsbcor obj = getNewTransientTtlsbcor(i);
            try {
                obj.persist();
            } catch (ConstraintViolationException e) {
                StringBuilder msg = new StringBuilder();
                for (Iterator<ConstraintViolation<?>> it = e.getConstraintViolations().iterator(); it.hasNext();) {
                    ConstraintViolation<?> cv = it.next();
                    msg.append("[").append(cv.getConstraintDescriptor()).append(":").append(cv.getMessage()).append("=").append(cv.getInvalidValue()).append("]");
                }
                throw new RuntimeException(msg.toString(), e);
            }
            obj.flush();
            data.add(obj);
        }
    }
}
